From b0c6be0a63e21e05771de89b3526bd2fe900ccf7 Mon Sep 17 00:00:00 2001 From: robertlipe Date: Sun, 22 Mar 2015 00:31:17 +0000 Subject: [PATCH] Gleb Smirinoff contributes vertical speed calculation for use with subrip. (There are probably edge cases about tracks with and without valid alt....) --- gpsbabel/defs.h | 1 + gpsbabel/subrip.cc | 10 ++++++++ gpsbabel/waypt.cc | 23 +++++++++++++++++++ .../xmldoc/formats/options/subrip-format.xml | 6 ++++- 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/gpsbabel/defs.h b/gpsbabel/defs.h index 2c284d789..6a06920db 100644 --- a/gpsbabel/defs.h +++ b/gpsbabel/defs.h @@ -866,6 +866,7 @@ void waypt_status_disp(int total_ct, int myct); double waypt_time(const Waypoint* wpt); double waypt_speed(const Waypoint* A, const Waypoint* B); double waypt_speed_ex(const Waypoint* A, const Waypoint* B); +double waypt_vertical_speed(const Waypoint* A, const Waypoint* B); double waypt_course(const Waypoint* A, const Waypoint* B); double waypt_distance(const Waypoint* A, const Waypoint* B); double waypt_distance_ex(const Waypoint* A, const Waypoint* B); diff --git a/gpsbabel/subrip.cc b/gpsbabel/subrip.cc index ffd95f6e3..9490aadf4 100644 --- a/gpsbabel/subrip.cc +++ b/gpsbabel/subrip.cc @@ -33,6 +33,7 @@ static time_t time_offset; static int stnum; static gbfile* fout; static const Waypoint* prevwpp; +static double vspeed; /* internal helper functions */ @@ -106,6 +107,9 @@ subrip_prevwp_pr(const Waypoint* waypointp) else gbfprintf(fout, " -"); break; + case 'v': + gbfprintf(fout, "%2.2f", vspeed); + break; case 't': { QTime t = prevwpp->GetCreationTime().toUTC().time(); @@ -159,6 +163,10 @@ subrip_trkpt_pr(const Waypoint* waypointp) * associated waypoint plus that of the following one. * Since we get waypoints one at a time, the only way is to store one and * defer processing until we get the next one. + * + * To determine vertical speed we need to have not only previous waypoint, + * but also pre-previous, so we calculate vspeed right before forgetting + * the previous. */ if ((stnum == 1) && (time_offset == 0)) /* @@ -174,6 +182,7 @@ subrip_trkpt_pr(const Waypoint* waypointp) if (prevwpp) { subrip_prevwp_pr(waypointp); + vspeed = waypt_vertical_speed(waypointp, prevwpp); } prevwpp = waypointp; } @@ -191,6 +200,7 @@ subrip_wr_init(const char* fname) time_offset = 0; prevwpp = NULL; + vspeed = 0; if ((opt_gpstime != NULL) && (opt_gpsdate != NULL)) { time(&gpstime_t); diff --git a/gpsbabel/waypt.cc b/gpsbabel/waypt.cc index 3cdbcdbe0..15706c5a1 100644 --- a/gpsbabel/waypt.cc +++ b/gpsbabel/waypt.cc @@ -541,6 +541,29 @@ waypt_speed(const Waypoint* A, const Waypoint* B) } } +/* + * Calculates the vertical speed between points "A" and "B" + * the result comes in meters per second and can be negative. + */ + +double +waypt_vertical_speed(const Waypoint* A, const Waypoint* B) +{ + double altitude, time; + + altitude = A->altitude - B->altitude; + if (altitude == 0) { + return 0; + } + + time = fabs((double)A->creation_time.msecsTo(B->creation_time)) / 1000.0; + if (time > 0) { + return (altitude / time); + } else { + return 0; + } +} + /* * Calculates "Course True" from A to B */ diff --git a/gpsbabel/xmldoc/formats/options/subrip-format.xml b/gpsbabel/xmldoc/formats/options/subrip-format.xml index 2f2b27e96..1d017a678 100644 --- a/gpsbabel/xmldoc/formats/options/subrip-format.xml +++ b/gpsbabel/xmldoc/formats/options/subrip-format.xml @@ -19,9 +19,13 @@ %e elevation in meters + + %v + vertical speed in m/s + %t - tiomestamp + timestamp %l -- 2.30.2